package com.cookman.handlers;

import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.cookman.controllers.AliceUI;
import com.cookman.renderers.BaseRenderer;
import com.cookman.serviceLocators.ServiceLocator;

/**
 * Created by Cookman on 18.09.14.
 */
public class CustomGestureHandler implements GestureDetector.GestureListener {

    public float initialScale = 1.0f;
    private float zoom = 1.0f;
    private BaseRenderer worldRenderer;

    public CustomGestureHandler(BaseRenderer worldRenderer) {
        this.worldRenderer = worldRenderer;
    }

    @Override
    public boolean touchDown(float x, float y, int pointer, int button) {
        initialScale = zoom;
        return false;
    }

    @Override
    public boolean zoom(float initialDistance, float distance) {
        //if(!((AliceUI) ServiceLocator.getUIController()).canSelectCities() || !ServiceLocator.getWorldRenderer().isModalVisible()) return false;
        //Calculate pinch to zoom
        float ratio = initialDistance / distance;
        //Clamp range and set zoom
        zoom = MathUtils.clamp(initialScale * ratio, 0.1f, 1.0f);
        worldRenderer.updateZoom(zoom);
        return true;
    }

    @Override
    public boolean panStop(float v, float v2, int i, int i2) {
        return false;
    }

    @Override
    public boolean tap(float v, float v2, int i, int i2) {
        return false;
    }

    @Override
    public boolean longPress(float v, float v2) {
        return false;
    }

    @Override
    public boolean fling(float v, float v2, int i) {
        return false;
    }

    @Override
    public boolean pan(float v, float v2, float v3, float v4) {
        return false;
    }

    @Override
    public boolean pinch(Vector2 vector2, Vector2 vector22, Vector2 vector23, Vector2 vector24) {
        return false;
    }
}

